/*
 * @Author: 李晓丹-=== 
 * @Date: 2021-02-23 14:26:07 
 * @Last Modified by: 李晓丹
 * @Last Modified time: 2021-02-23 14:36:31
 */

import {Switch,Route,Redirect} from 'react-router-dom';
import React,{FC} from 'react';
import {RouterInter} from './routerConfig';

import {RouteProps} from 'react-router';

interface Iprops{
    routes:RouterInter[]
}

const RouterView:FC<Iprops> = function({routes}){

    let routeArr = routes.filter((item:RouterInter) => item.component);
    let redirectArr = routes.filter((item:RouterInter) => item.redirect);
    return <Switch>
        {
            routeArr.map((item:RouterInter) => <Route key={item.path} path={item.path} render={(props:RouteProps) => {
                return <item.component {...props} routes={item.children}></item.component>
            }}></Route>)
        }
        {
            redirectArr.map((item:RouterInter) => <Redirect key={item.path} from={item.path} to={item.redirect as string}></Redirect>)
        }
    </Switch>
}

export default RouterView